package com.fitness.front.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fitness.front.convertor.VenueConvertor;
import com.fitness.front.mapper.VenueMapper;
import com.fitness.front.modal.resource.dto.VenueDto;
import com.fitness.front.modal.resource.entity.Venue;
import com.fitness.front.modal.resource.params.VenuePageQueryParams;
import com.fitness.front.modal.resource.vo.VenueVO;
import com.fitness.front.service.IVenueService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class VenueServiceImpl extends ServiceImpl<VenueMapper, Venue> implements IVenueService {

    private final VenueConvertor venueConvertor;

    @Override
    public Page<VenueVO> getVenuePage(VenuePageQueryParams queryParams) {
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        Page<VenueVO> page = new Page<>(pageNum, pageSize);

        Page<Venue> retPage = this.baseMapper.getVenuePage(page,queryParams);

        return venueConvertor.entity2vo(retPage);
    }

    @Override
    public boolean addVenue(VenueDto venueDto) {
        return save(venueConvertor.dto2entity(venueDto));
    }

    @Override
    public boolean updateVenue(VenueDto venueDto) {
        return updateById(venueConvertor.dto2entity(venueDto));
    }
}
